(function () {
  let data = {
    day365: { orders: '20,301,987', amount: '99834' },
    day90: { orders: '301,987', amount: '9834' },
    day30: { orders: '1,987', amount: '3834' },
    day1: { orders: '987', amount: '834' },
  };

  $('.filter a').on('click', function () {
    clearInterval(timer);
    nowIndex = $(this).index();
    $(this).addClass('active').siblings().removeClass('active');
    let key = $(this).attr('data-key');
    let dateK = data[key];
    // console.log(dateK);
    $('.order h4').eq(0).html(dateK.orders);
    $('.order h4').eq(1).html(dateK.amount);
    roll();
  });
  let nowIndex = 0;
  let timer;
  function roll() {
    timer = setInterval(function () {
      nowIndex++;
      if (nowIndex === $('.filter a').length) {
        nowIndex = 0;
      }
      $('.filter a').eq(nowIndex).trigger('click');
    }, 1000);
  }
  roll();
  // let timer;
  // timer = setInterval(function () {
  //   nowIndex++;
  //   if (nowIndex === $('.filter a').length) {
  //     nowIndex = 0;
  //   }
  //   $('.filter a').eq(nowIndex).click();
  // }, 1000);
})();
